<script setup>
	import {computed, ref} from "vue"
	import {onLoad} from "@dcloudio/uni-app"
	import {deliveryApi} from "@/apis/task.js"
		
	onLoad((options)=>{
		console.log(options.id);
		formData.value.id=options.id
	})
	
	const formData=ref({
		id:'',//id
		certificatePictureList:'',//提交上传回单凭证
		deliverPictureList:''//上传货品照片
	})
	
	//点击提交按钮校验
	const imgs=computed(()=>{
		return !formData.value.certificatePictureList.length||!formData.value.deliverPictureList.length
	})
	
	//点击提交后
	const submit=async()=>{
	    //转换图像
		formData.value.certificatePictureList=formData.value.certificatePictureList.map(({url})=>({url}))
		formData.value.deliverPictureList=formData.value.deliverPictureList.map(({url})=>({url}))
		// console.log(formData.value);
		await deliveryApi(formData.value)
		//提示
		uni.utils.message('交付成功')
		//跳转
		 uni.reLaunch({ url: '/pages/task/index' })
	}
</script>


<template> 
	<!-- 交付 -->
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker limit="3" v-model="formData.certificatePictureList" file-extname="jpg,webp,gif,png" title="请拍照上传回单凭证"></uni-file-picker>
      <uni-file-picker limit="3" title="请拍照上传货品照片" file-extname="jpg,webp,gif,png" v-model="formData.deliverPictureList"></uni-file-picker>
    </view>
    <button :disabled="imgs" class="button" @click="submit">提交</button>
  </view>
</template>


<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled] {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
